﻿using System.Web.Security;
using System.Web.Profile;

namespace StarfleetCommander.Models
{
    public class SfeMembershipProvider : SqlMembershipProvider
    {
        public SfeMembershipProvider():base()
        {
            FixConnectionString();
        }
        private void FixConnectionString()
        {
            // Update the private connection string field in the base class.
            var connectionString = StarfleetCommanderSecure.SqlConnectionStringManager.ConnectionString;

            // Set private property of Membership provider.
            var connectionStringField = GetType().BaseType.GetField("_sqlConnectionString",
                System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            connectionStringField.SetValue(this, connectionString);
        }
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            base.Initialize(name, config);
            FixConnectionString();

        }
    }
    public class SfeProfileProvider : SqlProfileProvider
    {
        public SfeProfileProvider()
            : base()
        {
            FixConnectionString();
        }
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            base.Initialize(name, config);
            FixConnectionString();
        }

        private void FixConnectionString()
        {
            // Update the private connection string field in the base class.
            var connectionString = StarfleetCommanderSecure.SqlConnectionStringManager.ConnectionString;

            // Set private property of Membership provider.
            var connectionStringField = GetType().BaseType.GetField("_sqlConnectionString",
                System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            connectionStringField.SetValue(this, connectionString);
        }
       
    }
}